package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.TraClassroom;
import com.ruoyi.bussiness.service.ITraClassroomService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训教室Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/classroom")
public class TraClassroomController extends BaseController
{
    private String prefix = "bussiness/classroom";

    @Autowired
    private ITraClassroomService traClassroomService;

    @RequiresPermissions("bussiness:classroom:view")
    @GetMapping()
    public String classroom()
    {
        return prefix + "/classroom";
    }

    /**
     * 查询培训教室列表
     */
    @RequiresPermissions("bussiness:classroom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TraClassroom traClassroom)
    {
        startPage();
        List<TraClassroom> list = traClassroomService.selectTraClassroomList(traClassroom);
        return getDataTable(list);
    }

    /**
     * 导出培训教室列表
     */
    @RequiresPermissions("bussiness:classroom:export")
    @Log(title = "培训教室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TraClassroom traClassroom)
    {
        List<TraClassroom> list = traClassroomService.selectTraClassroomList(traClassroom);
        ExcelUtil<TraClassroom> util = new ExcelUtil<TraClassroom>(TraClassroom.class);
        return util.exportExcel(list, "培训教室数据");
    }

    /**
     * 新增培训教室
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存培训教室
     */
    @RequiresPermissions("bussiness:classroom:add")
    @Log(title = "培训教室", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TraClassroom traClassroom)
    {
        return toAjax(traClassroomService.insertTraClassroom(traClassroom));
    }

    /**
     * 修改培训教室
     */
    @RequiresPermissions("bussiness:classroom:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TraClassroom traClassroom = traClassroomService.selectTraClassroomById(id);
        mmap.put("traClassroom", traClassroom);
        return prefix + "/edit";
    }

    /**
     * 修改保存培训教室
     */
    @RequiresPermissions("bussiness:classroom:edit")
    @Log(title = "培训教室", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TraClassroom traClassroom)
    {
        return toAjax(traClassroomService.updateTraClassroom(traClassroom));
    }

    /**
     * 删除培训教室
     */
    @RequiresPermissions("bussiness:classroom:remove")
    @Log(title = "培训教室", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(traClassroomService.deleteTraClassroomByIds(ids));
    }
}
